package com.cmccgz.udacs_landlord_webapp.data;

import android.support.annotation.NonNull;

import com.cmccgz.udacs_landlord_webapp.bean.AccreditCardBean;
import com.cmccgz.udacs_landlord_webapp.bean.MobileBean;

import java.util.List;

import static com.google.gson.internal.$Gson$Preconditions.checkNotNull;

/**
 * @author: Huang
 * @Descripion:
 * @date 2017/6/22 15:04
 */

public class HouseManagerRepository implements HouseManagerDataSource {

    private static HouseManagerRepository INSTANCE = null;

    private final HouseManagerDataSource mHouseRemoteDataSource;

    private final HouseManagerDataSource mHouseLocalDataSource;

    private HouseManagerRepository(@NonNull HouseManagerDataSource houseRemoteDataSource,
                            @NonNull HouseManagerDataSource houseLocalDataSource) {
        mHouseRemoteDataSource = checkNotNull(houseRemoteDataSource);
        mHouseLocalDataSource = checkNotNull(houseLocalDataSource);
    }

    public static HouseManagerRepository getInstance(HouseManagerDataSource tasksRemoteDataSource,
                                              HouseManagerDataSource tasksLocalDataSource) {
        if (INSTANCE == null) {
            INSTANCE = new HouseManagerRepository(tasksRemoteDataSource, tasksLocalDataSource);
        }
        return INSTANCE;
    }

    public static void destroyInstance() {
        INSTANCE = null;
    }


    @Override
    public void getFunctionList(@NonNull FunctionListCallback callback) {
        mHouseLocalDataSource.getFunctionList(callback);
    }

    @Override
    public void getHouseList(@NonNull String searchType, @NonNull String keyword, @NonNull String oCond, @NonNull int page, @NonNull HouseListCallback callback) {
        mHouseRemoteDataSource.getHouseList(searchType, keyword, oCond, page, callback);
    }

    @Override
    public void getHouseDetail(@NonNull String houseId, @NonNull HouseDetailCallback callback) {
        mHouseRemoteDataSource.getHouseDetail(houseId,callback);
    }

    @Override
    public void getBuildingCount(@NonNull String buildingId, @NonNull BuildingCountCallback callback) {
        mHouseRemoteDataSource.getBuildingCount(buildingId,callback);
    }


    @Override
    public void checkout(@NonNull List<MobileBean> bean, @NonNull String houseId,@NonNull BaseCallback callback) {
        mHouseRemoteDataSource.checkout(bean,houseId,callback);
    }

    @Override
    public void houseChange(@NonNull List<MobileBean> bean, @NonNull String oldHouseId, @NonNull String newHouseId,@NonNull BaseCallback callback) {
        mHouseRemoteDataSource.houseChange(bean, oldHouseId, newHouseId,callback);
    }

    /**
     * 开卡授权
     * @param bean
     * @param callback
     */
    @Override
    public void accreditCard(@NonNull AccreditCardBean bean, @NonNull BaseCallback callback) {
        mHouseRemoteDataSource.accreditCard(bean,callback);
    }
}
